package cn.com.pureAppApi.config;

import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;

import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.Parameter;
import com.github.pagehelper.PageInterceptor;

/**
 * InnoDB free: 10240 kB
 *
 * QQ讨论群:76989293
 * @email 2696701142@qq.com
 * @date 2018-06-12 16:51:48
 */
@Configuration
public class ConverterConfig  extends WebMvcConfigurerAdapter{


    
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
        FastJsonConfig fastJsonConfig = new FastJsonConfig();
        fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
        fastConverter.setFastJsonConfig(fastJsonConfig);
        converters.add(new StringHttpMessageConverter());
        converters.add(fastConverter);
    }

	@Bean
	public PageInterceptor pageInterceptor() {
		PageInterceptor interceptor = new PageInterceptor();
		Properties properties = new Properties();
		properties.put("helperDialect", "mysql");
		properties.put("reasonable", "true");
		properties.put("supportMethodsArguments", "true");
		properties.put("params", "count=countSql");
		interceptor.setProperties(properties);
		return interceptor;
	}
	

    @Bean
	public List<Parameter> parameter() {
		ParameterBuilder tokenParameterBuilder = new ParameterBuilder();
		tokenParameterBuilder.name("Token").description("认证用户token").modelRef(new ModelRef("string"))
				.parameterType("header").build();	
		List<Parameter> parameterList = new ArrayList<>();
		parameterList.add(tokenParameterBuilder.build());	
		return parameterList;
	}
}

